/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import javax.swing.plaf.TableHeaderUI;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * <p>Project: javase - T12
 * <p>Powered by webrx On 2021-12-27 09:07:47
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T12 {
    private int number;
    private ReadWriteLock lock = new ReentrantReadWriteLock();

    public void get() {
        lock.readLock().lock();
        String n = Thread.currentThread().getName();

        System.out.println(n + ":" + this.number);
        lock.readLock().unlock();
    }

    public void write(int number) {
        lock.writeLock().lock();
        String n = Thread.currentThread().getName();
        System.out.println(n + ":写操作");
        this.number = number;
        lock.writeLock().unlock();
    }
}
